Skip to content

[tests] Replace legacy [TestFixtureSetUp]/[TestFixtureTearDown] with [OneTimeSetUp]/[OneTimeTearDown]#1437

Merged
jonathanpeppers merged 1 commit into
mainfrom
jonathanpeppers/modernize-nunit-attributes
Jun 2, 2026
Merged

[tests] Replace legacy [TestFixtureSetUp]/[TestFixtureTearDown] with [OneTimeSetUp]/[OneTimeTearDown]#1437
jonathanpeppers merged 1 commit into
mainfrom
jonathanpeppers/modernize-nunit-attributes

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

The legacy [TestFixtureSetUp] and [TestFixtureTearDown] attributes were removed in NUnit 3 in favor of [OneTimeSetUp] and [OneTimeTearDown]. They have been kept around in NUnitLite for back-compat, which is why the on-device Android test path used them under #if __ANDROID__. NUnitLite also supports the modern OneTime* names, so the conditional is no longer needed.

This replaces the #if __ANDROID__ / #else / #endif blocks with the unconditional modern attribute in the three affected files:

  • tests/Java.Interop-Tests/Java.Interop/TestTypeTests.cs
  • tests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cs
  • tests/Java.Interop-Tests/Java.Interop/JavaArrayContract.cs

Why

This unblocks dotnet/android#11224, which migrates Mono.Android device tests from NUnitLite to stock NUnit 3.13.3 + MTP via dotnet test. Stock NUnit 3.13.3's netstandard2.0 assembly does not contain the legacy attribute names, so consuming Java.Interop's test code there currently requires a small compatibility shim (NUnitCompatibility.cs). After this change that shim can be deleted.

Verification

dotnet build tests/Java.Interop-Tests/Java.Interop-Tests.csproj succeeds.

…[OneTimeSetUp]/[OneTimeTearDown]

The legacy `[TestFixtureSetUp]` and `[TestFixtureTearDown]` attributes
were removed in NUnit 3 in favor of `[OneTimeSetUp]` and
`[OneTimeTearDown]`.  They have been kept around in NUnitLite for
back-compat, which is why the on-device Android test path used them
under `#if __ANDROID__`.  NUnitLite also supports the modern
`OneTime*` names, so the conditional is no longer needed.

Replacing the conditional with the unconditional modern attribute
unblocks dotnet/android#11224, which migrates Mono.Android device
tests from NUnitLite to stock NUnit 3.13.3 + MTP via `dotnet test`.
Stock NUnit 3.13.3's `netstandard2.0` assembly does not contain the
legacy attribute names, so consuming this code there currently
requires a small compatibility shim (NUnitCompatibility.cs).  After
this change that shim can be deleted.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 2, 2026 19:43
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, thanks! label Jun 2, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Java.Interop test fixtures to use NUnit 3’s modern one-time fixture lifecycle attributes consistently, removing Android-specific conditional compilation that depended on legacy NUnit2 attribute names. This aligns the test code with stock NUnit 3.x (netstandard2.0) and helps unblock downstream migration work.

Changes:

  • Replaced #if __ANDROID__ blocks using [TestFixtureSetUp]/[TestFixtureTearDown] with unconditional [OneTimeSetUp]/[OneTimeTearDown].
  • Applied the change across the three affected test fixtures/contracts to keep behavior consistent across platforms.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/Java.Interop-Tests/Java.Interop/TestTypeTests.cs Removes Android-only legacy NUnit2 attribute usage; uses OneTime* attributes unconditionally.
tests/Java.Interop-Tests/Java.Interop/JavaObjectArrayTest.cs Removes Android-only legacy NUnit2 attribute usage for global-ref counting setup/teardown.
tests/Java.Interop-Tests/Java.Interop/JavaArrayContract.cs Removes Android-only legacy NUnit2 attribute usage in the shared array contract base class.

Comment thread tests/Java.Interop-Tests/Java.Interop/TestTypeTests.cs
Comment thread tests/Java.Interop-Tests/Java.Interop/TestTypeTests.cs
@jonathanpeppers jonathanpeppers merged commit b982a1a into main Jun 2, 2026
3 checks passed
@jonathanpeppers jonathanpeppers deleted the jonathanpeppers/modernize-nunit-attributes branch June 2, 2026 23:39
jonathanpeppers added a commit to dotnet/android that referenced this pull request Jun 2, 2026
dotnet/java-interop#1437 replaces the legacy [TestFixtureSetUp] /
[TestFixtureTearDown] attributes with the modern [OneTimeSetUp] /
[OneTimeTearDown] names that stock NUnit 3 ships out of the box, so the
local NUnitCompatibility.cs shim is no longer needed.

Submodule bump:
  e38211334 -> b982a1a3 (dotnet/java-interop):
    b982a1a [tests] Replace [TestFixtureSetUp]/[TestFixtureTearDown] with [OneTimeSetUp]/[OneTimeTearDown] (#1437)
    e68fa0a Bump to dotnet/android-tools@3c95718 (#1436)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, thanks!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants